package com.tess.tboot.dao.mapper;

import com.tess.tboot.base.TbootBaseMapper;
import com.tess.tboot.entity.Role;
import com.tess.tboot.entity.User;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.session.RowBounds;

import java.util.List;
import java.util.Map;

/**
 * @author duanzonglong
 */
public interface RoleMapper extends TbootBaseMapper<Role> {
    /**
     * 获取默认角色
     * @param defaultRole
     * @return
     */
    @Select("select * from t_role where default_role=#{defaultRole}")
    List<Role> findByDefaultRole(Boolean defaultRole);

    @Select("<script>select count(1) from t_role where del_flag=0 " +
            "<when test='name!=null'> and username like '%'||#{name}||'%' </when>" +
            "<when test='access!=null'> and access = #{access} </when>" +
            "order by create_time desc</script>")
    int findByCond(Map<String,Object> params);

    @Select("<script>select * from t_role where del_flag=0 " +
            "<when test='name!=null'> and username like '%'||#{name}||'%' </when>" +
            "<when test='access!=null'> and mobile = #{access} </when>" +
            "order by create_time desc</script>")
    List<Role> findByCondWithPage(Map<String,Object> params, RowBounds rowBounds);
}
